package jp.co.menox.controller.tmserver.lend;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import jp.co.menox.controller.tmserver.TmServerControllerBase;
import jp.co.menox.tmcommon.model.Lending;
import jp.co.menox.tmcommon.model.LendingHistory;
import jp.co.menox.tmserver.service.CategoryService;
import jp.co.menox.tmserver.service.LendingHistoryService;
import jp.co.menox.tmserver.service.LendingService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class LendingApproveController extends TmServerControllerBase {

    protected LendingService lendingService;
    protected LendingHistoryService lendingHservice;
    protected CategoryService categoryService;
    {
        lendingService = new LendingService();
        lendingHservice = new LendingHistoryService();
        categoryService = new CategoryService();
    }
    

    @Override
    public Navigation run() throws Exception {
        String lendingHId = request.getParameter("lendHid");
        HttpSession session = request.getSession(true);
        long loginUserId = (Long)session.getAttribute("UserId");        
        long id = Long.parseLong(lendingHId);
        LendingHistory lendingHistory = lendingHservice.select(id);
        Lending lending = lendingService.select(lendingHistory.getLendingId());

        if (lendingHistory != null && lending != null) {
            // 表示用mapの取得
            Map<Long, String> categoryMap = categoryService.getCategoryMap();
            Map<Long, String> userMap = userService.getUserMap();
            // 表示用変数設定
            requestScope("lendingHistory", lendingHistory);
            requestScope("lending", lending);
            requestScope("cateMap", categoryMap);
            requestScope("userMap", userMap);
            requestScope("loginUserId", loginUserId);
        }
        
        
        return forward("lendingRegister.jsp");
     }
}
